﻿Imports System.Data.SqlClient
Imports System.Configuration
Imports MySQL
Imports MySQLCommand

Public Class LoginForm1

    ' TODO: Insert code to perform custom authentication using the provided username and password 
    ' (See http://go.microsoft.com/fwlink/?LinkId=35339).  
    ' The custom principal can then be attached to the current thread's principal as follows: 
    '     My.User.CurrentPrincipal = CustomPrincipal
    ' where CustomPrincipal is the IPrincipal implementation used to perform authentication. 
    ' Subsequently, My.User will return identity information encapsulated in the CustomPrincipal object
    ' such as the username, display name, etc.

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        If Trim(txtTenDN.Text) <> "" Then
            clsSQL.ExecReader("sp_USERSS_Login", txtTenDN.Text, txtMKhau.Text)
            clsSQL.getData.Read()
            If clsSQL.getData("Err") = 1 Then
                MaNVDangNhap = clsSQL.getData("UserName")
                TenNVDangNhap = clsSQL.getData("FullName")
                If clsSQL.getData("Access") = 1 Then

                Else
                    If clsSQL.getData("Access") = 2 Then ' nhap kho, quản lý sản phẩm
                        FrmMainForm.mniXuat.Enabled = False
                        FrmMainForm.mniAdmin.Enabled = False
                    Else
                        If clsSQL.getData("Access") = 3 Then 'xuất sản phẩm
                            FrmMainForm.mniNhap.Enabled = False
                            FrmMainForm.mniQLSP.Enabled = False
                            FrmMainForm.mniAdmin.Enabled = False
                        End If
                    End If
                End If
                ' MsgBox(clsSQL.getData("ErrMsg"))
                'Dim frm As New MainForm
                'frm.MdiParent = Me.MdiParent
                'frm.Show()
                FrmMainForm.Show()
                Me.Visible = False

            Else
                MsgBox(clsSQL.getData("ErrMsg"))
            End If


        Else
            MsgBox("Chưa nhập tên đăng nhập")
        End If



    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        End
    End Sub

    Private Sub LoginForm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        clsSQL.setConnection(ConfigurationSettings.AppSettings("Connect"))
        If clsSQL.Connected() = False Then
            MsgBox("Lỗi kết nối")
        End If
    End Sub
End Class
